<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>渠道环比</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border:none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:20px;">
                            <span>
                            <label class="item-label">年份：</label>
                            <input type="text" class="easyui-combobox" name="year" id="year" style="width:100px;"/>
                            </span>
                    <span id="monthLabel">
	                         <label class="item-label">月份：</label>
	                         <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/></span>
                    <span id="weekLabel">
	                         <label class="item-label">周数：</label>
	                         <input type="text" class="easyui-combobox" name="week" id="week" style="width:100px;"/></span>
                    <label class="item-label" id="label-for-channel" style="margin-left: 0px;">渠道：</label>
                    <input type="text" id="channelSelect" name="channelCode" class="easyui-textbox" data-options="panelHeight:'150'" style="width:5%;" />

                    <label class="item-label">品类：</label>
                    <input type="text" id="categorySelect" name="categoryCodes" class="easyui-combobox" data-options="panelHeight:'150'" style="width:6%"/>

                    <label class="item-label">期数：</label>
                    <select id="qs" name="qs" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:5%;" prompt="选值">
                        <option value="12">12</option>
                        <option value="11">11</option>
                        <option value="10">10</option>
                        <option value="9">9</option>
                        <option value="8">8</option>
                        <option value="7">7</option>
                        <option value="6">6</option>
                        <option value="5">5</option>
                        <option value="4">4</option>
                        <option  selected="selected" value="3">3</option>
                        <option value="2">2</option>
                        <option value="1">1</option>
                    </select>
                    <label class="item-label">占比：</label>
                    <select id="comparator" name="comparator" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:5%;" prompt="比较符">
                        <option value="GREAT">&gt;</option>
                        <option value="GREAT_EQUAL">&gt;=</option>
                    </select>
                    <input type="text" id="value" name="value" value="1" class="easyui-textbox" data-options="panelHeight:'150'" style="width:90px;" />
                    <a href="javascript:void(0);" style="margin-left:40px;width:80px;" class="easyui-linkbutton c8" onclick="searchBy()">查询</a>
                </div>
                <div style="margin-left: 3%"><span style="color: #5b81b3">注意：占比输入是百分之几 </span></div>
            </form>
        </div>
        <div class="table-wrapper " >
            <table id="datagrid">
                <thead>
                <tr>

                    <th data-options="field:'channelCode',align:'center'" width="80">渠道码</th>
                    <th data-options="field:'categoryName',align:'center'" width="80">品类</th>
                    <!--<th data-options="field:'categoryName',align:'center'" width="80">商场名</th>-->
                    <th data-options="field:'zb',align:'center',formatter:zeroReplace" width="80">量占比</th>
                    <th data-options="field:'zbpj',align:'center',formatter:zeroReplace" width="80">平均量占比</th>
                    <th data-options="field:'bq',align:'center',formatter:zeroReplace" width="100"><span style='color: red'>本期环比</span></th>
                    <th data-options="field:'hbpj',align:'center',formatter:zeroReplace" width="100"><span style='color: red'>前几期平均值</span></th>
                    <th data-options="field:'modelName',align:'center'" width="100"><span style='color: red'>异常原因</span></th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        setNav();
        // initCategoryMultiple();
        initCategorySelectnew("categorySelect");
        initChannelSelectshare("channelSelect");
        initMonthWeek("monthLabel","weekLabel");
        $('#channelCodeMulti').textbox({
            icons: [{
                iconCls: 'icon-clear', handler: function (e) {
                    $(e.data.target).textbox('clear');
                }
            }]
        });
        var height = $(window).height();
        var ff_height = $("#ff").height();
        var table_height = height - ff_height - 60;
        $("#datagrid").css("max-height", table_height);
        $("#datagrid").datagrid({
            rownumbers: true,
            // pagination: true,
            singleSelect: true,     //是否单选
            idField: "id",
            checkOnSelect: false,
            fitColumns:true,    //自动适应分辨率
            scrollbarSize:0     //滚动条大小
        }).datagrid("getPager").pagination({
            onSelectPage: searchBy
        });
    });

    function searchBy(){
        var data = getFormData(document.getElementById("ff"));
        data.reportType=window.parent.workMode.toUpperCase();
        $.ajax({
            type:"get",
            url:config.url + "/categoryMiss/channlControl",
            data:transfer(data),
            dataType: "json",
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            success:function(data){
                $.messager.progress("close");
                if (data.code == 200) {
                    $("#datagrid").datagrid("loadData", data.msg.content);
                }else {
                    $.messager.alert("提示", data.msg, "error");
                }
            },
            error:function(data){
                $.messager.progress("close");
            }
        });
    }

    function zeroReplace(val,row) {
        if (val) {
            if(val==-100000){
                return "+ ∞"
            }else{
                return val+"%";
            }


        }else {
            return "0.0%";
        }
    }
    function zeroReplace1(val,row) {
        if (val) {
            return val;

        }else {
            return 0;
        }
    }
    aRecords("量比环比","/webapp/pages/product/audit/channelRatio")
    function initChannelSelectshare(channelSelectId, mallSelectId, initCallback){
        var dtd = $.Deferred();
        $.ajax({
            url:config.url +"/channel/getAll",
            type:"get",
            xhrFields:{withCredentials:true},
            success:function (data) {
                if(data){
                    data.unshift({"name":"","code":""});
                    $("#"+channelSelectId).combobox({
                        "textField":"code",
                        "valueField":"code",
                        "panelHeight":"150",
                        "prompt":"--请选择--",
                        "data":data
                    });
                    dtd.resolve();
                    // 回调函数
                    if(typeof initCallback === "function"){
                        if(data.length>=2){
                            $("#"+channelSelectId).combobox('select', data[1]['code']);
                        }
                        initCallback();
                    }
                }
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                dtd.reject();
            }
        });
        return dtd.promise();
    }
</script>
</html>